package net.wanho.employ.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.wanho.employ.dto.AdminDTO;
import net.wanho.employ.entity.Admin;
import net.wanho.employ.service.AdminService;
import net.wanho.employ.vo.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * Author：汤小洋
 * Date：2024-03-25 15:40
 * Description：<描述>
 */
@Api(tags = "管理员接口")
@RestController
@RequestMapping("/admin")
public class AdminController {

    @Resource
    private AdminService adminService;

    @ApiOperation("查询列表")
    @GetMapping("/query")
    public AjaxResult query(@RequestParam(required = false, defaultValue = "1") @ApiParam("页码") int pageNum,
                            @RequestParam(required = false, defaultValue = "5") @ApiParam("页大小") int pageSize,
                            AdminDTO adminDTO){
        PageInfo<Admin> pageInfo = adminService.query(pageNum, pageSize, adminDTO);
        return AjaxResult.success(pageInfo);
    }

    @DeleteMapping("/removeMultiple")
    public AjaxResult removeMultiple(@RequestBody String[] ids){
        System.out.println(ids);
        return AjaxResult.success();
    }

    @PostMapping
    public AjaxResult add(@RequestBody Admin admin){
        adminService.add(admin);
        return AjaxResult.success();
    }

    @GetMapping("/{adminid}")
    public AjaxResult findById(@PathVariable String adminid){
        Admin admin = adminService.findById(adminid);
        return AjaxResult.success(admin);
    }

    @PutMapping
    public AjaxResult modify(@RequestBody Admin admin){
        adminService.modify(admin);
        return AjaxResult.success();
    }


}
